<extend name="Layout/ins_page" />
<block name="content">
	{:W('PageHeader/simple',array('name'=>'系统参数'))}
	<div class="layui-tab layui-tab-brief" >
		<ul class="layui-tab-title">
			<li>
				<a href="{:U('index')}">基本设置</a>
			</li>
			<li>
				<a href="{:U('weixin')}">微信设置</a>
			</li>
			<li>
				<a  href="{:U('weixin_menu')}">微信菜单</a>
			</li>
			<li class="layui-this">
				<a href="#">系统参数</a>
			</li>
			<li>
				<a  href="{:U('push')}">推送设置</a>
			</li>
		</ul>
	</div>
	<div class="sub-frame" >
		<input type="hidden" name="ajax" id="ajax" value="0">
		<select name="system_config_list" id="system_config_list" class="hidden">
			<option value="0">无</option>
			{:fill_option($system_config_list)}
		</select>
		<div class="oprator-panel">
			<div class="split"></div>
			<a id="btn_add" class="btn">新增</a>
			<a id="btn_save"  class="btn">保存</a>
			<span class="l">|</span>
			<a id="btn_del"  class="btn btn-del">删除</a>
		</div>
	</div>
	<!-- 功能操作区域结束 -->
	<!-- 列表显示区域  -->
	<div class="sub-frame">
		<form id="form_data_system" name="form_data_system" method="post">
			<input type="hidden" name="menu_id" id="menu_id" >
			<div class="sub-sidebar gray">
				<php>
					echo $menu
				</php>
			</div>
		</form>
		<div class="sub-content gray">
			<form id="form_data" name="form_data" method="post" class="common">
				<input type="hidden" name="id" id="id">
				<input type="hidden" name="data_type" value="common">
				<input type="hidden" name="opmode" id="opmode" value="">
				<div class="layui-sub-form-item ">
					<label class="layui-form-label" for="code">编码*：</label>
					<div class="layui-input-block">
						<input class="layui-input" type="text" id="code" name="code" check="required" info="请输入编码">
					</div>
				</div>
				<div class="layui-sub-form-item ">
					<label class="layui-form-label" for="name">名称*：</label>
					<div class="layui-input-block">
						<input class="layui-input" type="text" id="name" name="name" check="required" info="请输入名称">
					</div>
				</div>
				<div class="layui-sub-form-item ">
					<label class="layui-form-label" for="val">数据*：</label>
					<div class="layui-input-block">
						<input class="layui-input" type="text" id="val" name="val" check="required" info="请输入数据">
					</div>
				</div>
				<div class="layui-sub-form-item ">
					<label class="layui-form-label" for="pid_name">父级*：</label>
					<div class="layui-input-block">
						<input name="pid_name" class="layui-input" id="pid_name"  type="text" readonly="readonly" info="请选择父级" check="required"/>
						<input name="pid" id="pid" type="hidden" info="请选择上级部门" check="required" />
						<a class="add-on" id="btn_select_pid" type="button"> 选择 </a>
					</div>
				</div>

				<div class="layui-sub-form-item ">
					<label class="layui-form-label" for="sort">排序：</label>
					<div class="layui-input-block">
						<input class="layui-input" type="text" id="sort" name="sort" >
					</div>
				</div>

				<div class="layui-sub-form-item ">
					<label class="layui-form-label" for="is_del">状态*：</label>
					<div class="layui-input-block col-10 x-select">
						<select   name="is_del" id="is_del1" class="layui-input">
							<option  value="0">启用</option>
							<option value="1">禁用</option>
						</select>
					</div>
				</div>
			</form>
		</div>
	</div>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		layui.use('global', function() {
			var $ = layui.jquery;

			$(".tree_menu a").click(function() {
				$(".sub-sidebar .tree_menu a.active").removeClass("active");
				$(this).addClass("active");
				send_ajax("{:U('read')}", "id=" + $(this).attr("node") + "&name=", function(data) {
					showdata_common(data);
				});
				return false;
			});

			function showdata_common(result) {
				$("#form_data #code").val(result.data['code']);
				$("#form_data #name").val(result.data['name']);
				$("#form_data #val").val(result.data['val']);
				$("#form_data #sort").val(result.data['sort']);
				$("#form_data #is_del").val(result.data['is_del']);
				$("#form_data #remork").val(result.data['remork']);
				$("#form_data #pid").val(result.data['pid']);
				$("#form_data #id").val(result.data['id']);
				$("#form_data #pid_name").val($("#system_config_list option[value='" + result.data['pid'] + "']").text());
				$("#opmode").val("edit");
			};

			$("#btn_save").on('click', function() {
				send_form("form_data", "{:U('save')}", "{:U('config')}", function(ret) {
					if (ret.status) {
						layer.msg(ret.info, {
							time : 1200
						}, function() {
							parent.location.reload(true);
							parent.layer.close(index);
						});
					} else {
						layer.msg(ret.info);
						return false;
					}
				});
			});

			$("#btn_add").on('click', function() {
				winopen("{:U('add')}", 560, 470);
			});

			$("#btn_select_pid").on('click', function() {
				winopen("{:U('winpop')}", 560, 470);
			});

			$('#btn_del').on('click', function() {
				if ($(".sub-sidebar a.active").length == 0) {
					layer.msg('请选择要删除的数据');
					return false;
				}
				if ($(".sub-sidebar a.active").parent().find(".tree_menu").html() != undefined) {
					layer.msg('有子部门不能删除');
					return false;
				}
				//信息框-例2
				layer.msg('确定要删除吗?', {

					time : 0,
					btn : ['确定', '取消'],
					yes : function(index) {
						var vars = $("#form_data").serialize();
						send_ajax("{:U('del')}", vars, function(ret) {
							if (ret.status) {
								layer.msg(ret.info, {
									time : 1200
								}, function() {
									location.reload(true);
								});
							}
						});
					},
					no : function(index) {
						layer.close(index);
					}
				});
			});
		});
	</script>
</block>